﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using WebHoiChoMuaBan.Models;

namespace WebHoiChoMuaBan.Controllers.Helpers
{
    public class PageTypeHelper : HelperBase
    {
        private PageType pageType = null;
        
        public PageType PageType
        {
            get { return pageType; }
            set { pageType = value; }
        }

        public PageTypeHelper() : base()
        {

        }

        public PageType getPageType(int id)
        {
            this.pageType = this.dataContext.PageTypes.SingleOrDefault(p => p.PageId == id);

            if (this.pageType != null)
                this.pageType.IsEdit = true;
            return this.pageType;
        }

        public List<PageType> getAllPageTypes()
        {
            return (from p in this.dataContext.PageTypes
                    where p.PageStatus == true
                    select p).ToList();
        }

        public int CheckExistedPage(string pageName)
        {
            return (from page in this.dataContext.PageTypes
                    where page.PageName.Equals(pageName)
                     select page).Count();
        }

        //
        // Insert/Delete Methods

        public void Add(PageType page)
        {
            this.dataContext.PageTypes.InsertOnSubmit(page);
        }

        public void Save()
        {
            this.dataContext.SubmitChanges();
        }
    }
}